<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Alert</title>
    <style>
        /* 自定义 alert 样式 */
        .custom-alert {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            padding: 20px;
            border: 2px solid #ccc;
            box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
            z-index: 9999;
            display: none;
            width: 300px;
        }

        .custom-alert .alert-content {
            margin-bottom: 20px;
        }

        .custom-alert .alert-btn {
            padding: 10px 20px;
            background-color: #007BFF;
            color: white;
            border: none;
            cursor: pointer;
            border-radius: 4px;
        }

        .custom-alert .alert-btn:hover {
            background-color: #0056b3;
        }

        .custom-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 9998;
            display: none;
        }
    </style>
</head>

<body>

    <button onclick="alert('This is a custom alert!')">Show Alert</button>

    <!-- 自定义 alert 对话框 -->
    <div id="customAlert" class="custom-alert">
        <div class="alert-content" id="alertContent">This is a custom alert!</div>
        <button class="alert-btn" onclick="closeAlert()">OK</button>
    </div>

    <!-- 自定义遮罩层 -->
    <div id="customOverlay" class="custom-overlay"></div>

    <script>
        // 重写 alert 函数
        window.alert = function (message) {
            // 获取 alert 元素
            var alertBox = document.getElementById('customAlert');
            var alertContent = document.getElementById('alertContent');
            var overlay = document.getElementById('customOverlay');

            // 更新 alert 内容
            alertContent.textContent = message;

            // 显示 alert 和遮罩层
            alertBox.style.display = 'block';
            overlay.style.display = 'block';
        };

        // 关闭自定义 alert
        function closeAlert() {
            var alertBox = document.getElementById('customAlert');
            var overlay = document.getElementById('customOverlay');

            // 隐藏 alert 和遮罩层
            alertBox.style.display = 'none';
            overlay.style.display = 'none';
        }
    </script>

</body>

</html>